﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CompanyBussiness;

namespace Website.customer.Control
{
    public partial class cMenuMain : System.Web.UI.UserControl
    {
        NewsManagement newsMana = new NewsManagement();
        ProductManagement proMana = new ProductManagement();
        LanguagesManagement languageMana = new LanguagesManagement();
        TurnOverService overServices = new TurnOverService();
        CompanyBussiness.Language language;
        CompanyBussiness.TagTranslation tag;
        string modulCode;

        protected void Page_Load(object sender, EventArgs e)
        {
            modulCode = Request.QueryString["Mod"];
            loadModul();

            if (Request.Cookies[CONST.COOKIES_LANGUAGE] == null)
            {
                Session[CONST.SESSION_LANGUAGE] = "";
                language = languageMana.GetLanguageByCode("vi-VN");
            }
            else
            {
                Session[CONST.SESSION_LANGUAGE] = Request.Cookies[CONST.COOKIES_LANGUAGE][CONST.COOKIES_LANGUAGE_ID];
                language = languageMana.GetLanguageByID(int.Parse(Session[CONST.SESSION_LANGUAGE].ToString()));
            }
            loadLanguage();
            LoadMenu();
        }

        protected void loadLanguage()
        {
            lnkAboutUs.Text = languageMana.GetTagValueByLanguageIDandTagName("lnkAboutUs", language.LanguagesID);
            lnkNews.Text = languageMana.GetTagValueByLanguageIDandTagName("lnkNews", language.LanguagesID);
            lnkShareholder.Text = languageMana.GetTagValueByLanguageIDandTagName("lnkShareholder", language.LanguagesID);
            lnkProduct.Text = languageMana.GetTagValueByLanguageIDandTagName("lnkProduct", language.LanguagesID);
            lnkJob.Text = languageMana.GetTagValueByLanguageIDandTagName("lnkJob", language.LanguagesID);
            lnkHelp.Text = languageMana.GetTagValueByLanguageIDandTagName("lnkHelp", language.LanguagesID);
            lnkContact.Text = languageMana.GetTagValueByLanguageIDandTagName("lnkContact", language.LanguagesID);
        }

        protected void loadModul()
        {
            modulCode = Request.QueryString["Mod"];
            switch (modulCode)
            {
                case "MNEWS":
                    {
                        liNews.Attributes["class"] = "active";
                        lnkNews.Attributes["class"] = "active";
                    }
                    break;
                case "MSHAREHOLDERS":
                    {
                        liShareholder.Attributes["class"] = "active";
                        lnkShareholder.Attributes["class"] = "active";
                    }
                    break;
                case "MJOB":
                    {
                        liJob.Attributes["class"] = "active";
                        lnkJob.Attributes["class"] = "active";
                    }
                    break;
                case "MHELP":
                    {
                        liHelp.Attributes["class"] = "active";
                        lnkHelp.Attributes["class"] = "active";
                    }
                    break;
                case "MCONTACT":
                    {
                        liContact.Attributes["class"] = "active";
                        lnkContact.Attributes["class"] = "active";
                    }
                    break;
                case "MINTRO":
                    {
                        liAboutUs.Attributes["class"] = "active";
                        lnkAboutUs.Attributes["class"] = "active";
                    }
                    break;
                case "MPRODUCT":
                    {
                        liProduct.Attributes["class"] = "active";
                        lnkProduct.Attributes["class"] = "active";
                    }
                    break;
            }


        }

        protected void lnkAboutUs_Click(object sender, EventArgs e)
        {
            //menu gioi thieu
            //Response.Redirect("AboutUs.aspx?" + CONST.QUERYSTRING_CATEGORY + "=" + newsMana.GetTopParentCategoryID(language.LanguagesID, "MINTRO") + "&Mod=MINTRO");
            Response.Redirect("~/Hem/gioi-thieu/" + newsMana.GetTopParentCategoryID(language.LanguagesID, "MINTRO") + "/" + "MINTRO" + "/" + overServices.ConvertString(newsMana.GetNameCateByID(newsMana.GetTopParentCategoryID(language.LanguagesID, "MINTRO")).Replace(" ", "-")) + ".html");
        }

        protected void lnkNews_Click(object sender, EventArgs e)
        {
            //menu tin tuc
            //Response.Redirect("Newsroom.aspx?" + CONST.QUERYSTRING_CATEGORY + "=" + newsMana.GetTopParentCategoryID(language.LanguagesID, "MNEWS") + "&Mod=MNEWS");
            Response.Redirect("~/Hem/tin-tuc/" + newsMana.GetTopParentCategoryID(language.LanguagesID, "MNEWS") + "/" + "MNEWS" + "/" + overServices.ConvertString(newsMana.GetNameCateByID(newsMana.GetTopParentCategoryID(language.LanguagesID, "MNEWS")).Replace(" ", "-")) + ".html");
        }

        protected void lnkShareholder_Click(object sender, EventArgs e)
        {
            //menu quan he co dong
            //Response.Redirect("Shareholder.aspx?" + CONST.QUERYSTRING_CATEGORY + "=" + newsMana.GetTopParentCategoryID(language.LanguagesID, "MSHAREHOLDERS") + "&Mod=MSHAREHOLDERS");
            Response.Redirect("~/Hem/quan-he-co-dong/" + newsMana.GetTopParentCategoryID(language.LanguagesID, "MSHAREHOLDERS") + "/" + "MSHAREHOLDERS" + "/" + overServices.ConvertString(newsMana.GetNameCateByID(newsMana.GetTopParentCategoryID(language.LanguagesID, "MSHAREHOLDERS")).Replace(" ", "-")) + ".html");
        }

        protected void lnkProduct_Click(object sender, EventArgs e)
        {
            //san pham dich vu
            //Response.Redirect("Products.aspx?" + CONST.QUERYSTRING_TYPE_PRODUCT + "=" + proMana.GetTopTypeProductID(language.LanguagesID) + "&Mod=MPRODUCT");
            Response.Redirect("~/Hem/san-pham-dich-vu/" + proMana.GetTopTypeProductID(language.LanguagesID) + "/" + "MPRODUCT" + "/" + overServices.ConvertString(proMana.GetNametypeByID(proMana.GetTopTypeProductID(language.LanguagesID)).Replace(" ", "-")) + ".html");
        }

        protected void lnkJob_Click(object sender, EventArgs e)
        {
            //tuyen dung
            //Response.Redirect("Job.aspx?" + CONST.QUERYSTRING_CATEGORY + "=" + newsMana.GetTopParentCategoryID(language.LanguagesID, "MJOB") + "&Mod=MJOB");
            Response.Redirect("~/Hem/tuyen-dung/" + newsMana.GetTopParentCategoryID(language.LanguagesID, "MJOB") + "/" + "MJOB" + "/" + overServices.ConvertString(newsMana.GetNameCateByID(newsMana.GetTopParentCategoryID(language.LanguagesID, "MJOB")).Replace(" ", "-")) + ".html");
        }

        protected void lnkHelp_Click(object sender, EventArgs e)
        {
            //tro giup
            //Response.Redirect("Help.aspx?" + CONST.QUERYSTRING_CATEGORY + "=" + newsMana.GetTopParentCategoryID(language.LanguagesID, "MHELP") + "&Mod=MHELP");
            Response.Redirect("~/Hem/tro-giup/" + newsMana.GetTopParentCategoryID(language.LanguagesID, "MHELP") + "/" + "MHELP" + "/" + overServices.ConvertString(newsMana.GetNameCateByID(newsMana.GetTopParentCategoryID(language.LanguagesID, "MHELP")).Replace(" ", "-")) + ".html");
        }

        protected void lnkContact_Click(object sender, EventArgs e)
        {
            //lien he
            //Response.Redirect("Contact.aspx?Mod=MCONTACT");
            Response.Redirect("~/Hem/lien-he/" + "MCONTACT" + ".html");
        }

        protected void LoadMenu()
        {
            List<Category> listCateAboutUs = newsMana.GetParentCategoryAll(language.LanguagesID, "MINTRO");
            List<Category> listCateNews = newsMana.GetParentCategoryAll(language.LanguagesID, "MNEWS");
            List<Category> listCateShareholder = newsMana.GetParentCategoryAll(language.LanguagesID, "MSHAREHOLDERS");
            List<TypeProduct> listCateProduct = proMana.GetParentTypeProductAll(language.LanguagesID);
            List<Category> listCateJob = newsMana.GetParentCategoryAll(language.LanguagesID, "MJOB");
            List<Category> listCateHelp = newsMana.GetParentCategoryAll(language.LanguagesID, "MHELP");


            foreach (var a in listCateAboutUs)
            {
                MenuItem root = new MenuItem(a.CategoryName, a.CategoryID.ToString(), "", "~/Hem/gioi-thieu/" + a.CategoryID.ToString() + "/" + "MINTRO" + "/" + overServices.ConvertString(a.CategoryName.Replace(' ', '-')) + ".html");
                menuAboutUs.Items.Add(root);
                List<Category> listCateAboutUsChild = newsMana.GetChildrenCategoryByParentIDAll(a.CategoryID, language.LanguagesID, "MINTRO");
                foreach (var b in listCateAboutUsChild)
                {
                    MenuItem child = new MenuItem(b.CategoryName, b.CategoryID.ToString(), "", "~/Hem/gioi-thieu/" + b.CategoryID.ToString() + "/" + "MINTRO" + "/" + overServices.ConvertString(b.CategoryName.Replace(' ', '-')) + ".html");
                    root.ChildItems.Add(child);
                }
            }


            foreach (var a in listCateNews)
            {
                MenuItem root = new MenuItem(a.CategoryName, a.CategoryID.ToString(), "", "~/Hem/tin-tuc/" + a.CategoryID.ToString() + "/" + "MNEWS" + "/" + overServices.ConvertString(a.CategoryName.Replace(' ', '-')) + ".html");
                menuNews.Items.Add(root);
                List<Category> listCateChild = newsMana.GetChildrenCategoryByParentIDAll(a.CategoryID, language.LanguagesID, "MNEWS");
                foreach (var b in listCateChild)
                {
                    MenuItem child = new MenuItem(b.CategoryName, b.CategoryID.ToString(), "", "~/Hem/tin-tuc/" + b.CategoryID.ToString() + "/" + "MNEWS" + "/" + overServices.ConvertString(b.CategoryName.Replace(' ', '-')) + ".html");
                    root.ChildItems.Add(child);
                }
            }


            foreach (var a in listCateShareholder)
            {
                MenuItem root = new MenuItem(a.CategoryName, a.CategoryID.ToString(), "", "~/Hem/quan-he-co-dong/" + a.CategoryID.ToString() + "/" + "MSHAREHOLDERS" + "/" + overServices.ConvertString(a.CategoryName.Replace(' ', '-')) + ".html");
                menuShareholder.Items.Add(root);
                List<Category> listCateChild = newsMana.GetChildrenCategoryByParentIDAll(a.CategoryID, language.LanguagesID, "MSHAREHOLDERS");
                foreach (var b in listCateChild)
                {
                    MenuItem child = new MenuItem(b.CategoryName, b.CategoryID.ToString(), "", "~/Hem/quan-he-co-dong/" + b.CategoryID.ToString() + "/" + "MSHAREHOLDERS" + "/" + overServices.ConvertString(b.CategoryName.Replace(' ', '-')) + ".html");
                    root.ChildItems.Add(child);
                }
            }


            foreach (var a in listCateJob)
            {
                MenuItem root = new MenuItem(a.CategoryName, a.CategoryID.ToString(), "", "~/Hem/tuyen-dung/" + a.CategoryID.ToString() + "/" + "MJOB" + "/" + overServices.ConvertString(a.CategoryName.Replace(' ', '-')) + ".html");
                menuJob.Items.Add(root);
                List<Category> listCateChild = newsMana.GetChildrenCategoryByParentIDAll(a.CategoryID, language.LanguagesID, "MJOB");
                foreach (var b in listCateChild)
                {
                    MenuItem child = new MenuItem(b.CategoryName, b.CategoryID.ToString(), "", "~/Hem/tuyen-dung/" + b.CategoryID.ToString() + "/" + "MJOB" + "/" + overServices.ConvertString(b.CategoryName.Replace(' ', '-')) + ".html");
                    root.ChildItems.Add(child);
                }
            }


            foreach (var a in listCateHelp)
            {
                MenuItem root = new MenuItem(a.CategoryName, a.CategoryID.ToString(), "", "~/Hem/tro-giup/" + a.CategoryID.ToString() + "/" + "MHELP" + "/" + overServices.ConvertString(a.CategoryName.Replace(' ', '-')) + ".html");
                menuHelp.Items.Add(root);
                List<Category> listCateChild = newsMana.GetChildrenCategoryByParentIDAll(a.CategoryID, language.LanguagesID, "MHELP");
                foreach (var b in listCateChild)
                {
                    MenuItem child = new MenuItem(b.CategoryName, b.CategoryID.ToString(), "", "~/Hem/tro-giup/" + b.CategoryID.ToString() + "/" + "MHELP" + "/" + overServices.ConvertString(b.CategoryName.Replace(' ', '-')) + ".html");
                    root.ChildItems.Add(child);
                }
            }


            foreach (var a in listCateProduct)
            {
                MenuItem root = new MenuItem(a.TypeProductName, a.TypeProductID.ToString(), "", "~/Hem/san-pham-dich-vu/" + a.TypeProductID.ToString() + "/" + "MPRODUCT" + "/" + overServices.ConvertString(proMana.GetNametypeByID(a.TypeProductID).Replace(" ", "-")) + ".html");
                menuProduct.Items.Add(root);
                List<TypeProduct> listCateChild = proMana.GetChildrenTypeProductByParentIDAll(a.TypeProductID, language.LanguagesID);
                foreach (var b in listCateChild)
                {
                    MenuItem child = new MenuItem(b.TypeProductName, b.TypeProductID.ToString(), "", "~/Hem/san-pham-dich-vu/" + b.TypeProductID.ToString() + "/" + "MPRODUCT" + "/" + overServices.ConvertString(proMana.GetNametypeByID(b.TypeProductID).Replace(" ", "-")) + ".html");
                    root.ChildItems.Add(child);
                }
            }


        }
    }
}